import Cookies from 'js-cookie'

const TokenKey = 'Admin-Token'
const UserInfo = 'Admin-UserInfo'

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}


export function getUserInfo() {
  let data
  try {
    data = Cookies.get(UserInfo)
    data = JSON.parse(data)
  } catch (err) {
    data = ''
  }
  return data
}

export function setUserInfo(userInfo) {
  const data = JSON.stringify(userInfo)
  return Cookies.set(UserInfo, data)
}

export function removeUserInfo() {
  return Cookies.remove(UserInfo)
}
